define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'evaluation/evaluation/index' + location.search,
                    add_url: 'evaluation/evaluation/add',
                    edit_url: 'evaluation/evaluation/edit',
                    editconfig_url: 'evaluation/evaluation/editconfig',
                    del_url: 'evaluation/evaluation/del',
                    import_url: 'evaluation/evaluation/import',
                    multi_url: 'evaluation/evaluation/multi',
                    table: 'evaluation',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'sort', title: __('序号')},
                        {field: 'typename', title: __('Typename'), operate:false},
                        {field: 'name', title: __('Name'), operate:'LIKE'},
                        {field: 'scalar_id', title: __('Scalar_id'), operate:false},
                        {field: 'image', title: __('Image'), operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'introduce', title: __('Introduce'), operate:'LIKE'},
                        {field: 'tag', title: __('Tag'), operate:'LIKE'},
                        {field: 'age', title: __('Age'), operate:false},
                        {field: 'number', title: __('Number'), operate:false},
                        {field: 'timelong', title: __('Timelong'), operate:false},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        //{field: 'origin_price', title: __('Origin_price'), operate:'BETWEEN'},
                        //{field: 'buy_numbers', title: __('Buy_numbers')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'scalar_id', title: __('Scalar_id'), searchList: {"7":__('Scalar_id 7'),"21":__('Scalar_id 21'),"28":__('Scalar_id 28'),"50":__('Scalar_id 50'),"52":__('Scalar_id 52'),"54":__('Scalar_id 54'),"73":__('Scalar_id 73'),"83":__('Scalar_id 83'),"84":__('Scalar_id 84'),"85":__('Scalar_id 85')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: false,
                commonSearch: false,
                search:true,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                }
            });
            if($(Table.config.importbtn).size() > 0){
                require(['upload'], function(Upload){
                    Upload.api.plupload($(Table.config.importbtn), function(data, res, layero){
                        Toastr.success(res.msg);
                        Layer.closeAll();
                        Fast.api.close();
                        $(".btn-refresh").trigger('click');//刷新当前页面的数据
                    }, function(res){
                        //console.log('res222', res);
                        //Toastr.success(res.msg);
                    })
                })
            }
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        editconfig: function () {
            Controller.api.bindevent();
        },
        import: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});